Skip to content

Upgrade onnx runtime#1764

Merged
jpggvilaca merged 6 commits intomainfrom
jvilaca/upgrade-onnx-runtime
Apr 17, 2026
Merged

Upgrade onnx runtime#1764
jpggvilaca merged 6 commits intomainfrom
jvilaca/upgrade-onnx-runtime

Conversation

@jpggvilaca
Copy link
Copy Markdown
Contributor

@jpggvilaca jpggvilaca commented Mar 31, 2026

📝 Description

  • New onnx-runtime version provides support for webgpu.

Manual tests:
Before:
Screenshot 2026-04-17 at 09 03 54

After
Screenshot 2026-04-17 at 09 03 27

Next steps will be: Update opencv to the latest version, and lastly, update our old Sam1 model to Sam2.1

✨ Type of Change

Select the type of change your PR introduces:

  • 🐞 Bug fix – Non-breaking change which fixes an issue
  • 🚀 New feature – Non-breaking change which adds functionality
  • 🔨 Refactor – Non-breaking change which refactors the code base
  • 💥 Breaking change – Changes that break existing functionality
  • 📚 Documentation update
  • 🔒 Security update
  • 🧪 Tests

🧪 Testing Scenarios

Describe how the changes were tested and how reviewers can test them too:

  • ✅ Tested manually
  • 🤖 Run automated end-to-end tests

✅ Checklist

Before submitting the PR, ensure the following:

  • 🔍 PR title is clear and meaningful
  • ✍️ PR description clearly explains the changes and their reason
  • 📝 I have linked the PR to the corresponding GitHub Issues, if any
  • 💬 I have commented my code, especially in hard-to-understand areas
  • 📄 I have made corresponding changes to the documentation
  • ✅ I have added tests that prove my fix is effective or my feature works

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Upgrades the @geti/smart-tools web ONNX Runtime dependency to a newer onnxruntime-web version to enable the webgpu execution provider, and updates the Segment Anything pipeline/session setup to work with the new runtime behavior (including worker-safe tensor passing).

Changes:

  • Bump onnxruntime-web to ~1.24.3 (and update the root package-lock.json accordingly).
  • Update WASM/runtime configuration and default execution providers to prefer webgpu, plus serialize InferenceSession.run() calls.
  • Make Segment Anything encoder output structured-clone safe by returning a plain-object tensor representation and reconstructing the tensor in the decoder.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
web_ui/packages/smart-tools/src/utils/wasm-utils.ts Adjusts session defaults (WebGPU+CPU) and switches to a new WASM asset path/type.
web_ui/packages/smart-tools/src/segment-anything/session.ts Updates ORT env/session creation usage and adds run-call serialization to avoid concurrent run() on a single session.
web_ui/packages/smart-tools/src/segment-anything/segment-anything-encoder.ts Converts encoder output tensor into a serializable representation suitable for worker transfers.
web_ui/packages/smart-tools/src/segment-anything/segment-anything-decoder.ts Reconstructs an ort.Tensor from the serialized encoder output for decoder execution.
web_ui/packages/smart-tools/package.json Bumps onnxruntime-web dependency version.
web_ui/package-lock.json Locks updated onnxruntime-web/onnxruntime-common and transitive dependency versions.
Files not reviewed (1)
  • web_ui/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web_ui/packages/smart-tools/src/utils/wasm-utils.ts Outdated
Comment thread web_ui/packages/smart-tools/src/segment-anything/session.ts
Comment thread web_ui/packages/smart-tools/src/segment-anything/segment-anything-encoder.ts Outdated
@jpggvilaca jpggvilaca changed the title [DRAFT] Upgrade onnx runtime Upgrade onnx runtime Apr 17, 2026
@jpggvilaca jpggvilaca force-pushed the jvilaca/upgrade-onnx-runtime branch from 44b8836 to 2ddb683 Compare April 17, 2026 07:55
// array data so the decoder can reconstruct a valid tensor.
const encoderResult: SerializableTensor = {
data: (await gpuTensor.getData()) as Float32Array,
dims: [...gpuTensor.dims],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be gpuTensor.dims?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to clone things, but we could maybe make them read-only. In any case i will update on my next PR

return await this.ortSession.run(input);
// onnxruntime-web does not support concurrent run() calls on the same session.
// Serialize calls through a void queue so the result type stays clean.
const runNext = this.runQueue.then(() => this.ortSession!.run(input));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we make sure we have ortSession, i.e. not use !?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100%, agree. Let me update on the next PR

return await this.ortSession.run(input);
// onnxruntime-web does not support concurrent run() calls on the same session.
// Serialize calls through a void queue so the result type stays clean.
const runNext = this.runQueue.then(() => this.ortSession!.run(input));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand why we need this, could u please explain more?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts from Claude, but the gist is that each run() waits for the previous one before starting, so results always resolve in call order.

In any case i agree this is confusing so i will refactor this as well on my next PR. It will be something like:

const next = this.runQueue.catch(() => {}).then(() => session.run(input));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should cancel ongoing processing if there is a new one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to wait for it. The user clicked so it's intentional. Worry not. The next version will be much simpler :)

@jpggvilaca jpggvilaca added this pull request to the merge queue Apr 17, 2026
Merged via the queue into main with commit cd71c95 Apr 17, 2026
28 checks passed
@jpggvilaca jpggvilaca deleted the jvilaca/upgrade-onnx-runtime branch April 17, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants